<?php


namespace App;


use Encore\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Movies
 *
 * @property-read \App\MoviAuther $auther
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Movies[] $children
 * @property-read int|null $children_count
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\MoviComment[] $comments
 * @property-read int|null $comments_count
 * @property mixed $image
 * @property-read \App\Movies $parent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Movies newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Movies newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Movies query()
 * @mixin \Eloquent
 */
class Movies extends Model
{
    use ModelTree;

    public function __construct(array $attributes = [])
    {
//        $this->setParentColumn('');
//        $this->setOrderColumn('');
        parent::__construct($attributes);
    }

    protected $casts = [
        'extra' => 'json',
    ];
    public function auther()
    {
        return $this->hasOne(MoviAuther::class, 'movi_id', 'id');
    }

    /**
     * 评论
     */
    public function comments()
    {
        return $this->hasMany(MoviComment::class, 'movi_id', 'id');
    }

    public function setImageAttribute($image)
    {
        if (is_array($image)) {
            $this->attributes['image'] = json_encode($image);
        }
    }

    public function getImageAttribute($image)
    {
        return json_decode($image, true);
    }




}
